package fr.afcepf.ai89.esharing.tests;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import fr.afcepf.ai89.esharing.entity.Aem;
import fr.afcepf.ai89.esharing.entity.Avis;
import fr.afcepf.ai89.esharing.entity.Emprunt;
import fr.afcepf.ai89.esharing.entity.LibelleSousAvis;
import fr.afcepf.ai89.esharing.entity.NoteAvis;
import fr.afcepf.ai89.esharing.entity.Proprietaire;
import fr.afcepf.ai89.esharing.entity.SousAvis;
import fr.afcepf.ai89.esharing.entity.Valeur;
import fr.afcepf.ai89.esharing.metier.BusinessApprovisionnerCriteres;
import fr.afcepf.ai89.esharing.metier.BusinessCommuication;
import fr.afcepf.ai89.esharing.metier.BusinessEmpruntAem;
import fr.afcepf.ai89.esharing.metier.IBusinessApprovisionnerCriteres;
import fr.afcepf.ai89.esharing.metier.IBusinessCommunication;
import fr.afcepf.ai89.esharing.metier.IBusinessEmpruntAem;

public class BusinessEmpruntAemTest {
	
	public static void main(String[] args) {
		
		IBusinessEmpruntAem busEmpAem = new BusinessEmpruntAem();
		
		/*
		
		Emprunt emp = new Emprunt();
		
		emp.setAem(new Aem());
		emp.setProprietaire(new Proprietaire());
		
		emp.getAem().setIdAem(14);
		emp.getProprietaire().setIdUtilisateur(4);
		
		emp.setDateDebut(new Date(114, 04, 05));
		emp.setDateFin(new Date(114, 04, 10));
		
		int goodNumber = busEmpAem.demanderEmprunt(emp);
		
		System.out.println(goodNumber);
		
		*/
		
		/*
		
		List<Emprunt> tousLesEmprunts = busEmpAem.getEmprunts();
		
		for (Emprunt emp : tousLesEmprunts) {
			
			// In effect, if a Motivation Annulation or Refus is null, the string getChoix & c. can't be accessed 
			// even as nulls. To watch in controleur !!!!!!!!!
			
			System.out.println(emp.getIdEmprunt() + " de " + 
							   emp.getAem().getProprietaire().getNomUtilisateur() + " à " + 
							   emp.getProprietaire().getNomUtilisateur() + " " +
							   emp.getAem().getMarque().getMarque() + " " + 
							   emp.getAem().getTypeAem().getTypeAem() + " " + 
							   String.valueOf(emp.getDateDemande()) + " " + 
							   String.valueOf(emp.getDateDebut()) + " " + 
							   String.valueOf(emp.getDateFin()) + " " + 
							   String.valueOf(emp.getDateValidation()) + " " +
							   String.valueOf(emp.getDateRestitution()) + " " +
							   String.valueOf(emp.getDateAnnulation()) + " " + 
							 //  String.valueOf(emp.getMotivationAnnulation().getChoixMotivationAnnulation()) + " " + 
							   String.valueOf(emp.getDateRefus()) + " " + 
							 //   + " " + String.valueOf(emp.getMotivationRefus().getChoixMotivationRefus()));
			
		}
		
		*/
		
		/* 
		
		int idNico = 3;
		Proprietaire nico = new Proprietaire();
		nico.setIdUtilisateur(3);
		Emprunt emprunt = new Emprunt();
		emprunt.setAem(new Aem());
		emprunt.getAem().setIdAem(22);
		emprunt.setProprietaire(nico);
		emprunt.setDateDebut(new Date(114, 05, 05));
		emprunt.setDateFin(new Date(114, 05, 07));
		
		int nouveauEmpruntDeNico = busEmpAem.demanderEmprunt(emprunt);
		
		*/
		
		/*
		
		Emprunt nouveauDemandeDeNico = busEmpAem.getEmprunt(7);
		
		System.out.println(nouveauDemandeDeNico.getIdEmprunt() + " de " +  
						   nouveauDemandeDeNico.getAem().getProprietaire().getNomUtilisateur() + " à " + 
						   nouveauDemandeDeNico.getProprietaire().getNomUtilisateur() + " " +
						   nouveauDemandeDeNico.getAem().getMarque().getMarque() + " " + 
						   nouveauDemandeDeNico.getAem().getTypeAem().getTypeAem() + " " + 
						   String.valueOf(nouveauDemandeDeNico.getDateDemande()) + " " + 
						   String.valueOf(nouveauDemandeDeNico.getDateDebut()) + " " + 
						   String.valueOf(nouveauDemandeDeNico.getDateFin()));
		*/
		
		/*
		
		int id = 3;
		Proprietaire nico = new Proprietaire();
		nico.setIdUtilisateur(id);
		Double nicoSolde = new Double(0);
		nicoSolde = busEmpAem.afficherSolde(nico);
		
		System.out.println(nicoSolde.toString());
		
		*/
		
		/*
		
		Proprietaire nico = new Proprietaire();
		nico.setIdUtilisateur(3);
		
		List<Emprunt> tousLesEmprunts = busEmpAem.getEmprunts(nico);
		
		for (Emprunt emp : tousLesEmprunts) {
			
			// In effect, if a Motivation Annulation or Refus is null, the string getChoix & c. can't be accessed 
			// even as nulls. To watch in controleur !!!!!!!!!
			
			System.out.println(emp.getIdEmprunt() + " de " + 
							   emp.getAem().getProprietaire().getNomUtilisateur() + " à " + 
							   emp.getProprietaire().getNomUtilisateur() + " " +
							   emp.getAem().getMarque().getMarque() + " " + 
							   emp.getAem().getTypeAem().getTypeAem() + " " + 
							   String.valueOf(emp.getDateDemande()) + " " + 
							   String.valueOf(emp.getDateDebut()) + " " + 
							   String.valueOf(emp.getDateFin()) + " " + 
							   String.valueOf(emp.getDateValidation()) + " " +
							   String.valueOf(emp.getDateRestitution()) + " " +
							   String.valueOf(emp.getDateAnnulation()) + " " + 
							   // String.valueOf(emp.getMotivationAnnulation().getChoixMotivationAnnulation()) + " " + 
							   String.valueOf(emp.getDateRefus())
							   //  + " " + String.valueOf(emp.getMotivationRefus().getChoixMotivationRefus())
							   );
							   
		*/
		
		/*
		
		Proprietaire nico = new Proprietaire();
		nico.setIdUtilisateur(3);
		
		List<Emprunt> tousLesEmprunts = busEmpAem.getEmpruntsPasses(nico);
		
		for (Emprunt emp : tousLesEmprunts) {
			
			// In effect, if a Motivation Annulation or Refus is null, the string getChoix & c. can't be accessed 
			// even as nulls. To watch in controleur !!!!!!!!!
			
			System.out.println(emp.getIdEmprunt() + " de " + 
							   emp.getAem().getProprietaire().getNomUtilisateur() + " à " + 
							   emp.getProprietaire().getNomUtilisateur() + " " +
							   emp.getAem().getMarque().getMarque() + " " + 
							   emp.getAem().getTypeAem().getTypeAem() + " " + 
							   String.valueOf(emp.getDateDemande()) + " " + 
							   String.valueOf(emp.getDateDebut()) + " " + 
							   String.valueOf(emp.getDateFin()) + " " + 
							   String.valueOf(emp.getDateValidation()) + " " +
							   String.valueOf(emp.getDateRestitution()) + " " +
							   String.valueOf(emp.getDateAnnulation()) + " " + 
							   // String.valueOf(emp.getMotivationAnnulation().getChoixMotivationAnnulation()) + " " + 
							   String.valueOf(emp.getDateRefus())
							   //  + " " + String.valueOf(emp.getMotivationRefus().getChoixMotivationRefus())
							   );

			
		}
		
		*/
				
		/*
		
		Proprietaire ali = new Proprietaire();
		ali.setIdUtilisateur(2);
		
		List<Emprunt> tousLesEmprunts = busEmpAem.getEmpruntsAnnules(ali);
		
		for (Emprunt emp : tousLesEmprunts) {
			
			// In effect, if a Motivation Annulation or Refus is null, the string getChoix & c. can't be accessed 
			// even as nulls. To watch in controleur !!!!!!!!!
			
			System.out.println(emp.getIdEmprunt() + " de " + 
							   emp.getAem().getProprietaire().getNomUtilisateur() + " à " + 
							   emp.getProprietaire().getNomUtilisateur() + " " +
							   emp.getAem().getMarque().getMarque() + " " + 
							   emp.getAem().getTypeAem().getTypeAem() + " " + 
							   String.valueOf(emp.getDateDemande()) + " " + 
							   String.valueOf(emp.getDateDebut()) + " " + 
							   String.valueOf(emp.getDateFin()) + " " + 
							   String.valueOf(emp.getDateValidation()) + " " +
							   String.valueOf(emp.getDateRestitution()) + " " +
							   String.valueOf(emp.getDateAnnulation()) + " " + 
							   // String.valueOf(emp.getMotivationAnnulation().getChoixMotivationAnnulation()) + " " + 
							   String.valueOf(emp.getDateRefus())
							   //  + " " + String.valueOf(emp.getMotivationRefus().getChoixMotivationRefus())
							   );
		
		}
		
		*/
		
		/*

		Proprietaire flo = new Proprietaire();
		flo.setIdUtilisateur(4);
		
		List<Emprunt> tousLesEmprunts = busEmpAem.getEmpruntsRefuses(flo);
		
		for (Emprunt emp : tousLesEmprunts) {
			
			// In effect, if a Motivation Annulation or Refus is null, the string getChoix & c. can't be accessed 
			// even as nulls. To watch in controleur !!!!!!!!!
			
			System.out.println(emp.getIdEmprunt() + " de " + 
							   emp.getAem().getProprietaire().getNomUtilisateur() + " à " + 
							   emp.getProprietaire().getNomUtilisateur() + " " +
							   emp.getAem().getMarque().getMarque() + " " + 
							   emp.getAem().getTypeAem().getTypeAem() + " " + 
							   String.valueOf(emp.getDateDemande()) + " " + 
							   String.valueOf(emp.getDateDebut()) + " " + 
							   String.valueOf(emp.getDateFin()) + " " + 
							   String.valueOf(emp.getDateValidation()) + " " +
							   String.valueOf(emp.getDateRestitution()) + " " +
							   String.valueOf(emp.getDateAnnulation()) + " " + 
							   // String.valueOf(emp.getMotivationAnnulation().getChoixMotivationAnnulation()) + " " + 
							   String.valueOf(emp.getDateRefus())
							   //  + " " + String.valueOf(emp.getMotivationRefus().getChoixMotivationRefus())
							   );
		
		}

		*/
		
		/*
		
		Proprietaire nico = new Proprietaire();
		nico.setIdUtilisateur(3);
		
		List<Emprunt> tousLesEmprunts = busEmpAem.getEmpruntsEnCours(nico);
		
		for (Emprunt emp : tousLesEmprunts) {
			
			// In effect, if a Motivation Annulation or Refus is null, the string getChoix & c. can't be accessed 
			// even as nulls. To watch in controleur !!!!!!!!!
			
			System.out.println(emp.getIdEmprunt() + " de " + 
							   emp.getAem().getProprietaire().getNomUtilisateur() + " à " + 
							   emp.getProprietaire().getNomUtilisateur() + " " +
							   emp.getAem().getMarque().getMarque() + " " + 
							   emp.getAem().getTypeAem().getTypeAem() + " " + 
							   String.valueOf(emp.getDateDemande()) + " " + 
							   String.valueOf(emp.getDateDebut()) + " " + 
							   String.valueOf(emp.getDateFin()) + " " + 
							   String.valueOf(emp.getDateValidation()) + " " +
							   String.valueOf(emp.getDateRestitution()) + " " +
							   String.valueOf(emp.getDateAnnulation()) + " " + 
							   // String.valueOf(emp.getMotivationAnnulation().getChoixMotivationAnnulation()) + " " + 
							   String.valueOf(emp.getDateRefus())
							   //  + " " + String.valueOf(emp.getMotivationRefus().getChoixMotivationRefus())
							   );
		
		}
		
		*/
		
		/*
		
		Proprietaire nico = new Proprietaire();
		nico.setIdUtilisateur(3);
		
		List<Emprunt> tousLesEmprunts = busEmpAem.getEmpruntsPlannifies(nico);
		
		for (Emprunt emp : tousLesEmprunts) {
			
			// In effect, if a Motivation Annulation or Refus is null, the string getChoix & c. can't be accessed 
			// even as nulls. To watch in controleur !!!!!!!!!
			
			System.out.println(emp.getIdEmprunt() + " de " + 
							   emp.getAem().getProprietaire().getNomUtilisateur() + " à " + 
							   emp.getProprietaire().getNomUtilisateur() + " " +
							   emp.getAem().getMarque().getMarque() + " " + 
							   emp.getAem().getTypeAem().getTypeAem() + " " + 
							   String.valueOf(emp.getDateDemande()) + " " + 
							   String.valueOf(emp.getDateDebut()) + " " + 
							   String.valueOf(emp.getDateFin()) + " " + 
							   String.valueOf(emp.getDateValidation()) + " " +
							   String.valueOf(emp.getDateRestitution()) + " " +
							   String.valueOf(emp.getDateAnnulation()) + " " + 
							   // String.valueOf(emp.getMotivationAnnulation().getChoixMotivationAnnulation()) + " " + 
							   String.valueOf(emp.getDateRefus())
							   //  + " " + String.valueOf(emp.getMotivationRefus().getChoixMotivationRefus())
							   );
		
		}
		
		*/
		
		/*
		
		Proprietaire nico = new Proprietaire();
		nico.setIdUtilisateur(3);
		
		List<Emprunt> tousLesEmprunts = busEmpAem.getEmpruntsNonValides(nico);
		
		for (Emprunt emp : tousLesEmprunts) {
			
			// In effect, if a Motivation Annulation or Refus is null, the string getChoix & c. can't be accessed 
			// even as nulls. To watch in controleur !!!!!!!!!
			
			System.out.println(emp.getIdEmprunt() + " de " + 
							   emp.getAem().getProprietaire().getNomUtilisateur() + " à " + 
							   emp.getProprietaire().getNomUtilisateur() + " " +
							   emp.getAem().getMarque().getMarque() + " " + 
							   emp.getAem().getTypeAem().getTypeAem() + " " + 
							   String.valueOf(emp.getDateDemande()) + " " + 
							   String.valueOf(emp.getDateDebut()) + " " + 
							   String.valueOf(emp.getDateFin()) + " " + 
							   String.valueOf(emp.getDateValidation()) + " " +
							   String.valueOf(emp.getDateRestitution()) + " " +
							   String.valueOf(emp.getDateAnnulation()) + " " + 
							   // String.valueOf(emp.getMotivationAnnulation().getChoixMotivationAnnulation()) + " " + 
							   String.valueOf(emp.getDateRefus())
							   //  + " " + String.valueOf(emp.getMotivationRefus().getChoixMotivationRefus())
							   );
		
		}
		
		*/
		
		/*
		
		Proprietaire nico = new Proprietaire();
		nico.setIdUtilisateur(3);
		
		List<Emprunt> tousLesEmprunts = busEmpAem.getEmpruntsNonValides(nico);
		
		for (Emprunt emp : tousLesEmprunts) {
			
			// In effect, if a Motivation Annulation or Refus is null, the string getChoix & c. can't be accessed 
			// even as nulls. To watch in controleur !!!!!!!!!
			
			System.out.println(emp.getIdEmprunt() + " de " + 
							   emp.getAem().getProprietaire().getNomUtilisateur() + " à " + 
							   emp.getProprietaire().getNomUtilisateur() + " " +
							   emp.getAem().getMarque().getMarque() + " " + 
							   emp.getAem().getTypeAem().getTypeAem() + " " + 
							   String.valueOf(emp.getDateDemande()) + " " + 
							   String.valueOf(emp.getDateDebut()) + " " + 
							   String.valueOf(emp.getDateFin()) + " " + 
							   String.valueOf(emp.getDateValidation()) + " " +
							   String.valueOf(emp.getDateRestitution()) + " " +
							   String.valueOf(emp.getDateAnnulation()) + " " + 
							   // String.valueOf(emp.getMotivationAnnulation().getChoixMotivationAnnulation()) + " " + 
							   String.valueOf(emp.getDateRefus())
							   //  + " " + String.valueOf(emp.getMotivationRefus().getChoixMotivationRefus())
							   );
		
		}
		
		*/
		
		/*
		
		Aem machinTruc = new Aem();
		machinTruc.setIdAem(22);
		
		List<Emprunt> tousLesEmprunts = busEmpAem.getEmprunts(machinTruc);
		
		for (Emprunt emp : tousLesEmprunts) {
			
			// In effect, if a Motivation Annulation or Refus is null, the string getChoix & c. can't be accessed 
			// even as nulls. To watch in controleur !!!!!!!!!
			
			System.out.println(emp.getIdEmprunt() + " de " + 
							   emp.getAem().getProprietaire().getNomUtilisateur() + " à " + 
							   emp.getProprietaire().getNomUtilisateur() + " " +
							   emp.getAem().getMarque().getMarque() + " " + 
							   emp.getAem().getTypeAem().getTypeAem() + " " + 
							   String.valueOf(emp.getDateDemande()) + " " + 
							   String.valueOf(emp.getDateDebut()) + " " + 
							   String.valueOf(emp.getDateFin()) + " " + 
							   String.valueOf(emp.getDateValidation()) + " " +
							   String.valueOf(emp.getDateRestitution()) + " " +
							   String.valueOf(emp.getDateAnnulation()) + " " + 
							   // String.valueOf(emp.getMotivationAnnulation().getChoixMotivationAnnulation()) + " " + 
							   String.valueOf(emp.getDateRefus())
							   //  + " " + String.valueOf(emp.getMotivationRefus().getChoixMotivationRefus())
							   );
		
		}
		
		*/
		
		// Faut encore tester :
		// annulerEmprunt
		// majEmprunt
		// creerPanier
		// validerPanier
		
		Emprunt emp = busEmpAem.getEmprunt(10);
		
		emp.setAvisSurPreteur(new Avis());
		emp.getAvisSurPreteur().setCommentairesLibres("Super emprunt ! J'étais trop content.");
		emp.getAvisSurPreteur().setNoteAvis(new NoteAvis());
		emp.getAvisSurPreteur().getNoteAvis().setIdNote(5);
		
		List<SousAvis> sa = new ArrayList<SousAvis>();
		
			List<LibelleSousAvis> lsa = new ArrayList<LibelleSousAvis>();
			IBusinessApprovisionnerCriteres busApCrit = new BusinessApprovisionnerCriteres();
			lsa = busApCrit.getLibelleSousAvisSurPreteur();
			
			for (LibelleSousAvis l : lsa) {
				
				sa.add(new SousAvis());
				int last = sa.size() - 1;
				sa.get(last).setLibelleSousAvis(l);
				sa.get(last).setNoteAvis(new NoteAvis());
				sa.get(last).getNoteAvis().setIdNote(5);
				sa.get(last).setAvis(emp.getAvisSurPreteur());
				
			}
			
			emp.getAvisSurPreteur().setSousAvis(sa);
			
		int idEmprunt = busEmpAem.addAvisSurPreteur(emp);
		
		System.out.println(idEmprunt);
		
		
		
		
		
		
		

		
		// Here I need a method for deducting and adding the solde when the transaction is done... double method in DAO 
		// and single method from the Business point of view (appartenant au prêt) !
		
	}

}
